<% @title = "search" %>

<% if @error_msg %>
  <div class="errorExplanation">
    <p><%= @error_msg %></p>
  </div>
<% end %>
<%= link_to t("advanced_search"), advanced_search_path, class: "t-link--gray t-link--has-arrow" %>
<% if @yanked_filter %>
  <% @subtitle = t('.subtitle_html', :query => params[:query]) %>

  <% if @yanked_gem.present? %>
    <%= link_to rubygem_path(@yanked_gem.slug), :class => 'gems__gem' do %>
      <span class="gems__gem__info">
        <h2 class="gems__gem__name">
          <%= @yanked_gem.name %>
          <span class="gems__gem__badge"><%= t('searches.advanced.yanked') %></span>
        </h2>
        <p class="gems__gem__desc t-text"><%= t('rubygems.show_yanked.not_hosted_notice') %></p>
      </span>
    <% end %>
  <% end %>
<% else %>
  <% if @gems %>
    <% @subtitle = t('.subtitle_html', :query => params[:query]) %>

    <header class="gems__header push--s">
      <p class="gems__meter"><%= page_entries_info(@gems, :entry_name => 'gem') %></p>
    </header>

    <%= render partial: 'aggregations', locals: { gems: @gems } %>

    <% suggestions = es_suggestions(@gems) %>
    <% if suggestions %>
      <div class='search__suggestions'>
        <p>
          <%= t(".suggestion") %>
          <%= to_sentence(suggestions.map do |term|
            link_to term, search_path(params: { query: term }), only_path: true
          end, last_word_connector: ' or ') %>?
        </p>
      </div>
    <% end %>

    <% if @gems.present? %>
      <%= render partial: 'rubygems/rubygem', collection: @gems %>
      <%= paginate @gems %>
    <% end %>
  <% end %>
<% end %>
